﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


class SubsetEquelToSum
{
    
    static void Main(string[] args)
    {
        int[] MyArray = new int[] { 4, 13, 3, 6, 8, 11, 1, 9 };
        int sum = 13;
        int MaxCombination = (int)Math.Pow(2, MyArray.Length) - 1;
        for (int i = 1; i <= MaxCombination; i++)
        {
            string CurrentSubset = "";
            int tempSum = 0;
            for (int j = 0; j < MyArray.Length; j++)
            {

                int mask = 1 << j;
                int nAndMask = i & mask;
                int bit = nAndMask >> j;
                if (bit == 1)
                {
                    tempSum += MyArray[j];
                    CurrentSubset += MyArray[j].ToString() + " ";
                }

            }
            if (tempSum == sum)
            {
                Console.WriteLine("Subset {0}have sum {1}", CurrentSubset, sum);
            }
        }
    }

}
